﻿using System.Collections.Generic;
using System.Configuration;

namespace SQLRunnerLib.Util
{
    public class PlaceHolderConfig : ConfigurationSection
    {
        // Declare a collection element represented 
        // in the configuration file by the sub-section
        // <urls> <add .../> </urls> 
        // Note: the "IsDefaultCollection = false" 
        // instructs the .NET Framework to build a nested 
        // section like <urls> ...</urls>.
        [ConfigurationProperty("placeholders", IsDefaultCollection = false)]
        public PlaceHolderCollection PlaceHolders
        {
            get
            {
                PlaceHolderCollection phCollection = (PlaceHolderCollection)base["placeholders"];
                return phCollection;
            }
        }
        
        public Dictionary<string,string> PlaceHoldersDictionary
        {
            get
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();
                PlaceHolderCollection phs = PlaceHolders;
                if (phs != null)
                {
                    foreach (PlaceHolderElement el in phs)
                        dic[el.PlaceHolder.Trim().ToLower()] = el.Replacement.Trim().ToLower();
                }
                return dic;
            }
        }         
    }
}